/*
 * @Author: ReinerLau lk850593913@gmail.com
 * @Date: 2023-01-12 17:32:45
 * @LastEditors: ReinerLau lk850593913@gmail.com
 * @LastEditTime: 2023-01-13 11:06:44
 * @FilePath: \v2.0.0\cypress\e2e\patroling\patroling_path.cy.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
describe("围界车 - 初始化", () => {
  beforeEach(() => {
    const username = "admin";
    const password = "123456";
    cy.login(username, password);
  });

  it("创建路径并下发任务", () => {
    createPath();

    cy.contains("自主规划").click();

    cy.intercept("POST", "/api/robot-cruise/patrolingCruise/v2/**").as(
      "createMission"
    );

    cy.contains("下发任务").click();

    cy.wait("@createMission").its("request.body.length").should("eq", 2);

    cy.contains("发送成功").should("exist");
  });

  it("取消路径", () => {
    createPath();

    cy.contains("自主规划").click();

    cy.contains("取消路径").click();

    cy.contains("自主规划").click();

    cy.contains("下发任务").click();

    cy.contains("路径点为空").should("exist");
  });
});

function createPath() {
  cy.visit("/patroling/release");

  cy.getByData("patroling-car-switch").find("svg").eq(0).click();

  cy.getByData("patroling-bottom").find("div").eq(1).click();

  cy.wait(3 * 1000);

  cy.contains("自主规划").click();

  cy.contains("创建路径").click();

  cy.contains("创建路径").should("not.exist");

  cy.getByData("patroling-map").as("map");

  cy.get("@map").click(500, 500);

  cy.get("@map").dblclick(700, 500);
}
